home *** CD-ROM | disk | FTP | other *** search
/ C/C++ Users Group Library 1996 July / C-C++ Users Group Library July 1996.iso / vol_300 / 353_02 / schedule.cpp < prev    next >
C/C++ Source or Header  |  1992-01-18  |  8KB  |  251 lines

  1. #include <iostream.h>
  2. #include <stdio.h>
  3. #include <string.h>
  4. #include <conio.h>
  5. #include "flyaway.h"
  6. #include "schedule.h"
  7. #include "items.h"
  8. #include "map.h"
  9. #include "location.h"
  10. #include "clock.h"
  11.  
  12. extern location rest_room;
  13. extern location waiting_area;
  14. extern location gate1;
  15. extern location gate2;
  16. extern location gate3;
  17. extern location gate4;
  18. extern location plane1;
  19. extern location plane2;
  20. extern location plane3;
  21. extern location plane4;
  22.  
  23. extern items personal_items;
  24. extern clock time_of_day;
  25. extern words input_words;
  26. extern map airport;
  27.  
  28. int visited_rest_room = FALSE;   // TRUE if the rest room was visited
  29.                                  //  as checked in shuffle_gates
  30.  
  31. schedule::schedule(void)
  32. {
  33.    flight_number[0] = 222;
  34.    flight_number[1] = 17;
  35.    flight_number[2] = 141;
  36.    flight_number[3] = 79;
  37.    destination[0] = new char[7];
  38.       strcpy(destination[0], "HAWAII");
  39.    destination[1] = new char[7];
  40.       strcpy(destination[1], "PARIS ");
  41.    destination[2] = new char[7];
  42.       strcpy(destination[2], "ROME  ");
  43.    destination[3] = new char[7];
  44.       strcpy(destination[3], "TAHITI");
  45.    depart_hour[0] = 9;
  46.    depart_hour[1] = 9;
  47.    depart_hour[2] = 9;
  48.    depart_hour[3] = 9;
  49.    depart_minute[0] = 19;
  50.    depart_minute[1] = 17;
  51.    depart_minute[2] = 16;
  52.    depart_minute[3] = 18;
  53.    gate[0] = &gate1;
  54.    gate[1] = &gate2;
  55.    gate[2] = &gate3;
  56.    gate[3] = &gate4;
  57.    flights_frozen = FALSE;
  58.    gates_frozen = FALSE;
  59.    my_gate = 0;
  60. }
  61.  
  62.  
  63. void schedule::shuffle_flights(void)
  64. {
  65.    if (!flights_frozen)             // Until flights are frozen,
  66.       my_gate = (my_gate + 1) % 4;  //  select the next flight
  67.                                     //  at the next gate.
  68. }
  69.  
  70.  
  71. void schedule::shuffle_gates(void)
  72. {
  73. int temp;
  74. char *temp_point;
  75.  
  76.    if (airport.get_current_location() == &rest_room)
  77.       visited_rest_room = TRUE;
  78.  
  79.    if ((airport.get_current_location() ==
  80.                                  gate[my_gate]) && (!gates_frozen)) {
  81.  
  82.       temp             = flight_number[0];
  83.       flight_number[0] = flight_number[1];
  84.       flight_number[1] = flight_number[2];
  85.       flight_number[2] = flight_number[3];
  86.       flight_number[3] = temp;
  87.  
  88.       temp_point     = destination[0];
  89.       destination[0] = destination[1];
  90.       destination[1] = destination[2];
  91.       destination[2] = destination[3];
  92.       destination[3] = temp_point;
  93.  
  94.       temp           = depart_hour[0];
  95.       depart_hour[0] = depart_hour[1];
  96.       depart_hour[1] = depart_hour[2];
  97.       depart_hour[2] = depart_hour[3];
  98.       depart_hour[3] = temp;
  99.  
  100.       temp             = depart_minute[0];
  101.       depart_minute[0] = depart_minute[1];
  102.       depart_minute[1] = depart_minute[2];
  103.       depart_minute[2] = depart_minute[3];
  104.       depart_minute[3] = temp;
  105.  
  106.       my_gate = (my_gate + 3) % 4;  // Subtract one from my_gate
  107.  
  108.       cout <<
  109.          "A message is heard on the airport paging system, \"All"
  110.          " gates\nhave been rescheduled due to bad weather.  No "
  111.          "flights have\nbeen cancelled at this time.\"\n";
  112.  
  113.    }
  114. }
  115.  
  116.  
  117.                                 // This freezes the gate assignments
  118. void schedule::list_flights(location *current_location)
  119. {
  120.    if (current_location == &waiting_area)
  121.       gates_frozen = TRUE;
  122.  
  123.    for (int index = 0 ; index < 4 ; index++) {
  124.       printf("Gate %d - Flight %3d - %s - ",
  125.               (index + 1),
  126.               flight_number[index],
  127.               destination[index]);
  128.       list_time(index);
  129.    }
  130. }
  131.  
  132.  
  133. void schedule::gate_message(location *current_location)
  134. {
  135. int index;
  136.  
  137.               // Find gate we are at and print message
  138.    for (index = 0;index < 4;index++)
  139.       if (current_location == gate[index]) goto gate_is_found;
  140.  
  141.    return;    // If not a gate
  142.  
  143.    gate_is_found:
  144.    printf("Flight %3d - %s - ",     // If a gate is found
  145.            flight_number[index],
  146.            destination[index]);
  147.    list_time(index);
  148. }
  149.  
  150.  
  151.                                    // This freezes the players flight
  152. void schedule::list_actual_destination(void)
  153. {
  154.       flights_frozen = TRUE;
  155.  
  156.       printf("Flight %3d - %s - ",
  157.            flight_number[my_gate],
  158.            destination[my_gate]);
  159.       list_time(my_gate);
  160. }
  161.  
  162.  
  163. void schedule::list_time(int index)
  164. {
  165.    if (depart_minute[index] < 10)
  166.       printf("%d:0%d\n",depart_hour[index], depart_minute[index]);
  167.    else
  168.       printf("%d:%d\n",depart_hour[index], depart_minute[index]);
  169. }
  170.  
  171.  
  172. void schedule::check_flight(void)
  173. {
  174.  
  175.    if ((airport.get_current_location() == &plane1) ||
  176.          (airport.get_current_location() == &plane2) ||
  177.            (airport.get_current_location() == &plane3) ||
  178.              (airport.get_current_location() == &plane4)) {
  179.  
  180.                                             // You must have a ticket
  181.       if (!personal_items.item_here(ticket))
  182.          cout <<
  183.          "Unfortunately, you don't have a ticket, you are arrested\n"
  184.          "as a stowaway and drug off the plane screaming.  No vaca-\n"
  185.          "tion for you.\n";
  186.  
  187.                                             // On plane 1 from gate 1
  188.       else if ((airport.get_current_location() == &plane1) &&
  189.                                                       (my_gate != 0))
  190.          cout <<
  191.          "Unfortunately, you are at gate 1 and this flight is going\n"
  192.          " to " << destination[0] << ".  Better luck next time.\n";
  193.  
  194.                                             // On plane 2 from gate 2
  195.       else if ((airport.get_current_location() == &plane2) &&
  196.                                                       (my_gate != 1))
  197.          cout <<
  198.          "Unfortunately, you are at gate 2 and this flight is going\n"
  199.          " to " << destination[1] << ".  Better luck next time.\n";
  200.  
  201.                                             // On plane 3 from gate 3
  202.       else if ((airport.get_current_location() == &plane3) &&
  203.                                                       (my_gate != 2))
  204.          cout <<
  205.          "Unfortunately, you are at gate 3 and this flight is going\n"
  206.          " to " << destination[2] << ".  Better luck next time.\n";
  207.  
  208.                                             // On plane 4 from gate 4
  209.       else if ((airport.get_current_location() == &plane4) &&
  210.                                                       (my_gate != 3))
  211.          cout <<
  212.          "Unfortunately, you are at gate 4 and this flight is going\n"
  213.          " to " << destination[3] << ".  Better luck next time.\n";
  214.  
  215.                                                // You must be on time
  216.       else if ((time_of_day.present_hour() > depart_hour[my_gate]) ||
  217.                (time_of_day.present_minute() > depart_minute[my_gate]))
  218.          cout <<
  219.          "Unfortunately, you are too late for your flight and are\n"
  220.          "aboard a cargo plane to Greasy Creek, Missouri.  Better\n"
  221.          "luck next time.\n";
  222.  
  223.                                                // You must have candy
  224.       else if (!personal_items.item_here(candy))
  225.          cout <<
  226.          "Unfortunately, you failed to bring any food along and you\n"
  227.          "died of malnutrition half way to your destination.\n";
  228.  
  229.                                       // You must visit the rest room
  230.       else if (!visited_rest_room)
  231.          cout <<
  232.          "Unfortunately, you forgot to take care of your bladder\n"
  233.          "problem back at the airport.  The restrooms on this plane\n"
  234.          "are out-of-order.  You suffer a ruptured bladder and die\n"
  235.          "enroute to your destination.\n";
  236.  
  237.                              // A successful trip through the airport
  238.       else
  239.          cout <<
  240.          "Congratulations, you are comfortably enroute to your well\n"
  241.          "deserved vacation.  You can study the source code to this\n"
  242.          "program on the plane.  If you do not have the source code,\n"
  243.          "you can read the paper in the lobby for the address where\n"
  244.          "you can write for more information.\n";
  245.  
  246.       cout  << "\nHit any key to end the game.\n";
  247.       getch();                  // Wait for ke